<?php

  session_start();
  include "config.php";
  include "ALcustomer.php";

  if(isset($_SESSION["user"]))
  {
    include "$header";
    include "$body";

?>

<div style="position:absolute; top:0px; left:1px; border:0;">
  <span class="prevPage">Order Products:Search > </span>
  <span class="page">Confirm Customer Details</span>
</div>
  
<?php

    include "$H_op";
    if(isset($_GET["continue"]))
    {
      $customerDetails = getCustomerDetails2($_SESSION["c_no"]);
      if($customerDetails[21] == "N")
      {
        echo "<SCRIPT language='Javascript'>";
        echo "  alert('The customer has unpaid credit card payments from previous orders.  Please order when those payments are completed.');";
        echo "  window.location.href = 'orderProducts.php';";
        echo "</SCRIPT>";
      }
      else
      {
        $_SESSION["o_confirmed"] = true;
        echo "<SCRIPT language='Javascript'>";
        echo "  window.location.href = 'orderProducts_2orderProducts.php';";
        echo "</SCRIPT>";
      }
    }
    elseif(isset($_GET["change"]))
    {
      echo "<SCRIPT language='Javascript'>";
      echo "  window.location.href = 'changeCustomerDetails.php';";
      echo "</SCRIPT>";
    }
    else
    {
      $customerDetails = getCustomerDetails2($_SESSION["c_no"]);
      showForm();
      echo "<SCRIPT language='Javascript'>";
      echo "  customerForm.title.value = '" . $customerDetails[0] . "';";
      echo "  customerForm.surname.value = '" . $_SESSION["c_surname"] . "';";
      echo "  customerForm.given_name.value = '" . $_SESSION["c_given_name"] . "';";
      echo "  customerForm.dob_day.value = '" . $_SESSION["c_day"] . "';";
      echo "  customerForm.dob_month.value = '" . getMonth($_SESSION["c_month"]) . "';";
      echo "  customerForm.dob_year.value = '" . $_SESSION["c_year"] . "';";
      echo "  customerForm.address.value = '" . $_SESSION["c_address"] . "';";
      echo "  customerForm.pcode.value = '" . $_SESSION["c_pcode"] ."';";
      echo "  customerForm.ph_area1.value = '" . $customerDetails[1] . "';";
      echo "  customerForm.ph_no1.value = '" . $customerDetails[2] . "';";
      echo "  customerForm.ph_area2.value = '" . $customerDetails[3] . "';";
      echo "  customerForm.ph_no2.value = '" . $customerDetails[4] . "';";
      echo "  customerForm.card_type1.value = '" . $customerDetails[5] . "';";
      echo "  customerForm.card_name1.value = '" . $customerDetails[10] . "';";
      echo "  customerForm.card_no1_1.value = '" . $customerDetails[6] . "';";
      echo "  customerForm.card_no1_2.value = '" . $customerDetails[7] . "';";
      echo "  customerForm.card_no1_3.value = '" . $customerDetails[8] . "';";
      echo "  customerForm.card_no1_4.value = '" . $customerDetails[9] . "';";
      echo "  customerForm.card_expiry_month1.value = '" . getMonth($customerDetails[11]) . "';";
      echo "  customerForm.card_expiry_year1.value = '20" . $customerDetails[12] . "';";
      $_SESSION["o_alternate"] = false;
      if($customerDetails[13] != "")
      {
        echo "  customerForm.card_type2.value = '" . $customerDetails[13] . "';";
        echo "  customerForm.card_name2.value = '" . $customerDetails[18] . "';";
        echo "  customerForm.card_no2_1.value = '" . $customerDetails[14] . "';";
        echo "  customerForm.card_no2_2.value = '" . $customerDetails[15] . "';";
        echo "  customerForm.card_no2_3.value = '" . $customerDetails[16] . "';";
        echo "  customerForm.card_no2_4.value = '" . $customerDetails[17] . "';";
        echo "  customerForm.card_expiry_month2.value = '" . getMonth($customerDetails[19]) . "';";
        echo "  customerForm.card_expiry_year2.value = '20" . $customerDetails[20] . "';";
        $_SESSION["o_alternate"] = true;
      }
      echo "</SCRIPT>";
    }
    include "$footer";
  }
  else
  {
    session_destroy();
    echo "<SCRIPT language='Javascript'>";
    echo "  parent.window.location.href = 'index.php';";
    echo "</SCRIPT>";
  }

  function showForm()
  {
?>

<p>

<b>CURRENT CUSTOMER DETAILS</b>

<p>
<FORM name="customerForm" action="" method="get">
<TABLE class="customer" cellpadding="5" cellspacing="5">
  <TR>
    <TD class="cField">
      Title<font color="red">*</font>
    </TD>
    <TD class="cDetails">
      <input type="text" class="customerConfirm" name="title" style="width:70px;" readonly />
    </TD>
  </TR>
  <TR>
    <TD class="cField">
	  Surname<font color="red">*</font>
	</TD>
    <TD class="cDetails">
	  <input type="text" class="customerConfirm" name="surname" style="width:150px;" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField">
	  Given Name<font color="red">*</font>
	</TD>
	<TD class="cDetails">
	  <input type="text" class="customerConfirm" name="given_name" style="width:150px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField">
	  Date of Birth<font color="red">*</font>
	</TD>
	<TD class="cDetails">
      <input type="text" class="customerConfirm" name="dob_day" style="width:40px;" readonly />
      <input type="text" class="customerConfirm" name="dob_month" style="width:90px" readonly />
      <input type="text" class="customerConfirm" name="dob_year" style="width:60px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField">
	  Address<font color="red">*</font>
	</TD>
	<TD class="cDetails">
	  <input type="text" class="customerConfirm" name="address" style="width:150px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField">
	  Post Code<font color="red">*</font>
	</TD>
	<TD class="cDetails">
	  <input type="text" class="customerConfirm" name="pcode" style="width:150px" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField">
      Phone (H)/(M)<font color="red">*</font>
      <br />(W)
	</TD>
	<TD class="cDetails">
      ( <input type="text" class="customerConfirm" name="ph_area1" style="width:30px;" readonly /> )
      <input type="text" class="customerConfirm" name="ph_no1" style="width:100px;" readonly /><br />
      ( <input type="text" class="customerConfirm" name="ph_area2" style="width:30px;" readonly /> )
      <input type="text" class="customerConfirm" name="ph_no2" style="width:100px;" readonly />
	</TD>
  </TR>
  <TR>
    <TD class="cField" valign="top">
      Preferred Credit Card<font color="red">*</font>
	</TD>
	<TD class="cDetails">
      <TABLE style="border:1px solid #000000">
        <TR>
          <TD>
            Card Type: &nbsp; <input type="text" class="customerConfirm" name="card_type1" style="width:100px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Card Name: &nbsp; <input type="text" class="customerConfirm" name="card_name1" style="width:150px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Card Number: &nbsp; 
            <input type="text" class="customerConfirm" name="card_no1_1" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no1_2" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no1_3" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no1_4" style="width:40px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Expiry Date: &nbsp; <input type="text" class="customerConfirm" name="card_expiry_month1" style="width:100px;" readonly />
            <input type="text" class="customerConfirm" name="card_expiry_year1" style="width:75px;" readonly />
          </TD>
        </TR>
      </TABLE>
	</TD>
  </TR>
  <TR>
    <TD class="cField" valign="top">
      Alternate Credit Card
	</TD>
	<TD class="cDetails">
      <TABLE style="border:1px solid #000000">
        <TR>
          <TD>
            Card Type: &nbsp; <input type="text" class="customerConfirm" name="card_type2" style="width:100px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Card Name: &nbsp; <input type="text" class="customerConfirm" name="card_name2" style="width:150px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Card Number: &nbsp; <input type="text" class="customerConfirm" name="card_no2_1" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no2_2" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no2_3" style="width:40px;" readonly />
            <input type="text" class="customerConfirm" name="card_no2_4" style="width:40px;" readonly />
          </TD>
        </TR>
        <TR>
          <TD>
            Expiry Date: &nbsp; <input type="text" class="customerConfirm" name="card_expiry_month2" style="width:100px;" readonly />
            <input type="text" class="customerConfirm" name="card_expiry_year2" style="width:75px;" readonly />
          </TD>
        </TR>
      </TABLE>
	</TD>
  </TR>
</TABLE>
<p>
<input class="order_confirm_off" type="submit" value="Change Details" name="change" onmouseover="className='order_confirm_on'" onmouseout="className='order_confirm_off'" />
&nbsp;&nbsp;
<input class="order_confirm_off" type="submit" value="Continue To Order..." name="continue" onmouseover="className='order_confirm_on'" onmouseout="className='order_confirm_off'" />
</FORM>

<p>
&nbsp;
</p>

</BODY>

<?php

  }

  function getMonth($month)
  {
    if($month == "01")
    {
      return "January";
    }
    else if($month == "02")
    {
      return "February";
    }
    else if($month == "03")
    {
      return "March";
    }
    else if($month == "04")
    {
      return "April";
    }
    else if($month == "05")
    {
      return "May";
    }
    else if($month == "06")
    {
      return "June";
    }
    else if($month == "07")
    {
      return "July";
    }
    else if($month == "08")
    {
      return "August";
    }
    else if($month == "09")
    {
      return "September";
    }
    else if($month == "10")
    {
      return "October";
    }
    else if($month == "11")
    {
      return "November";
    }
    else if($month == "12")
    {
      return "December";
    }
    else
    {
      echo "error in getmonth()";
    }
  }
  
?>